# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ois
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3
_oisver=${pkgver/./-}
pkgrel=2
pkgdesc="Object Oriented Input System (mingw-w64)"
arch=('any')
url="https://sourceforge.net/projects/wgois"
license=('custom:zlib/libpng')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' '!libtool' 'staticlibs')
makedepends=('autoconf' 'automake' 'libtool' "${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://downloads.sourceforge.net/project/wgois/Source%20Release/${pkgver}/ois_v${_oisver}.tar.gz"
        "gcc47.patch"
        "configure.patch"
        "demos.patch"
        "win32joystick.patch"
        "win32forcefeedback.patch"
        "win32keyboard.patch"
        "win32mouse.patch"
        "win32prereqs.patch")
sha256sums=('50fa76d827e119a80e2c86a5196ac4354e556f80b0a4fa440f69e1057b37faa1'
            'c3aa98125bb696cd03be520a150068e651adf77814602d5f3475292046a619e2'
            '982460de6379cd3d1231c83fa1094af3cdfb923431e825108f3ade71af7ea21a'
            'e112a0de6c2c3ea2ef0c53c3ecdc71eb68af067744ba5ad50a2b6fc9d58c2f1a'
            '4537d1d77e22cc73aa88a83b0a62eca202e5c69ad78227c708dc0776aceff277'
            '4b7fbc802fb274ddb53ae3de8590da62a63728def6901608dffb32ce38ed1c97'
            '3a9623c5854cdb34799dfe4b36c6533de62829519531d892c2d1b238022ff7a2'
            'e9bb423f21fb75079072eddd19048e108eae73144f7ae2e59ca4181948d7bf33'
            '81992e1cfbf18d547058fd92b4c4f6d592bb50aaba44c5152b45aa5e0ba9b424')

prepare() {
  cd ${srcdir}/ois-v${_oisver}

  patch -Nbp1 < ${srcdir}/gcc47.patch
  patch -Nbp1 < ${srcdir}/configure.patch
  patch -Nbp1 < ${srcdir}/demos.patch
  patch -Nbp1 < ${srcdir}/win32joystick.patch
  patch -Nbp1 < ${srcdir}/win32forcefeedback.patch
  #patch -Nbp1 < ${srcdir}/win32keyboard.patch
  patch -Nbp1 < ${srcdir}/win32mouse.patch
  patch -Nbp1 < ${srcdir}/win32prereqs.patch

  libtoolize --copy --force
  aclocal ${ACLOCAL_FLAGS}
  autoheader
  automake --include-deps --add-missing --foreign --copy
  autoconf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../ois-v${_oisver}/configure \
     --prefix=${MINGW_PREFIX} \
     --build=${MINGW_CHOST} \
     --host=${MINGW_CHOST} \
     --enable-shared=yes \
     --enable-static=yes
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
